clear 
import excel "G:\My Drive\Research Paper\CT.xlsx", sheet("Sheet1") firstrow 
destring d1- d17 , replace
gen log_nearest_dist_city = ln(NearestCiitywithPopulationof)
gen nearest_dist_city = NearestCiitywithPopulationof
gen NEAR_DIST_km_sq = (NEAR_DIST_km)^2
gen log_nearest_dist_city_sq = (log_nearest_dist_city)^2  
gen nearest_dist_city_sq = (nearest_dist_city)^2  
label var  NEAR_DIST_km "Highway road distance(in km)"
gen log_NEAR_DIST_km =ln(NEAR_DIST_km)
gen log_NEAR_DIST_km_sq = (log_NEAR_DIST_km)^2
label var  log_NEAR_DIST_km "Log of Highway road distance(in km)"
label  var  log_NEAR_DIST_km_sq "Square of Log of Highway road distance(in km)"
label var NEAR_DIST_km_sq "Square of Highway road distance(in km)"
label var log_nearest_dist_city "Log of Distance of nearest city/ST (in km)"
label var log_nearest_dist_city_sq  "Square of Log of Distance of nearest city/ST (in km)"
gen road_dis_city_dis = NEAR_DIST_km * nearest_dist_city
gen bank_hundred =  Nearestcitynoofbanks /100




*****Table 2 Summary Statistics **************
eststo clear 
estpost summ  CensusTowns  NEAR_DIST_km nearest_dist_city  Nearestcitynoofbanks
eststo
esttab using "G:\My Drive\Research Paper\summary.rtf", cells("count mean sd min max") abs  se(%9.2f) label replace starlevels(* .10 ** .05 *** .01) b(%9.2f) nomtitles
summ Nearestcitynoofbanks  if Nearestcitynoofbanks ~= 1007

************* Table 3 OLS Estimation*******************


eststo clear
reg  CensusTowns  NEAR_DIST_km bank_hundred d2- d17, robust
eststo 
reg  CensusTowns nearest_dist_city  bank_hundred d2- d17 , robust
eststo 
reg  CensusTowns nearest_dist_city  NEAR_DIST_km road_dis_city_dis bank_hundred d2- d17 , robust
eststo 
reg  CensusTowns nearest_dist_city  bank_hundred d2- d17  if Nearestcitynoofbanks ~= 1007 , robust
eststo 
reg  CensusTowns bank_hundred    NEAR_DIST_km d2- d17  if Nearestcitynoofbanks ~= 1007 , robust
eststo 
reg  CensusTowns bank_hundred   nearest_dist_city road_dis_city_dis   NEAR_DIST_km d2- d17  if Nearestcitynoofbanks ~= 1007 , robust
eststo 
esttab using "G:\My Drive\Research Paper\results_OLS.rtf", abs  se(%9.3f) label replace starlevels(* .10 ** .05 *** .01) b(%9.3f) r2(%9.3f) ar2(%9.3f) nomtitles


*************** Table 4 Logit Estimation*******************
eststo clear
logit  CensusTowns  NEAR_DIST_km bank_hundred d2- d17
margins,  dydx (NEAR_DIST_km bank_hundred) post
eststo
logit  CensusTowns nearest_dist_city  bank_hundred d2- d17 
margins,  dydx (nearest_dist_city  bank_hundred) post
eststo
logit  CensusTowns nearest_dist_city NEAR_DIST_km road_dis_city_dis bank_hundred d2- d17 
margins,  dydx (nearest_dist_city  NEAR_DIST_km bank_hundred road_dis_city_dis) post
eststo
logit  CensusTowns nearest_dist_city  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
margins,  dydx (nearest_dist_city  bank_hundred) post
eststo
logit  CensusTowns NEAR_DIST_km  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
margins,  dydx (NEAR_DIST_km  bank_hundred) post
eststo
logit  CensusTowns NEAR_DIST_km  nearest_dist_city road_dis_city_dis  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
margins,  dydx (NEAR_DIST_km   nearest_dist_city bank_hundred road_dis_city_dis) post
eststo
esttab using "G:\My Drive\Research Paper\results_LOGIT.rtf", abs  se(%9.3f) label replace starlevels(* .10 ** .05 *** .01) b(%9.3f) r2(%9.3f) ar2(%9.3f) nomtitles

**********Table 5 Probit Estimation*******************
eststo clear
probit  CensusTowns  NEAR_DIST_km bank_hundred d2- d17
margins,  dydx (NEAR_DIST_km bank_hundred) post
eststo
probit  CensusTowns nearest_dist_city  bank_hundred d2- d17 
margins,  dydx (nearest_dist_city  bank_hundred) post
eststo
probit  CensusTowns nearest_dist_city NEAR_DIST_km road_dis_city_dis bank_hundred d2- d17 
margins,  dydx (nearest_dist_city  NEAR_DIST_km bank_hundred road_dis_city_dis) post
eststo
probit  CensusTowns nearest_dist_city  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
margins,  dydx (nearest_dist_city  bank_hundred) post
eststo
probit  CensusTowns NEAR_DIST_km  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
margins,  dydx (NEAR_DIST_km  bank_hundred) post
eststo
probit  CensusTowns NEAR_DIST_km  nearest_dist_city road_dis_city_dis bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
margins,  dydx (NEAR_DIST_km nearest_dist_city  bank_hundred road_dis_city_dis) post
eststo
esttab using "G:\My Drive\Research Paper\results_PROBIT.rtf", abs  se(%9.3f) label replace starlevels(* .10 ** .05 *** .01) b(%9.3f) r2(%9.3f) ar2(%9.3f) nomtitles



eststo clear 

******Goodness of fit  of Table 2 *************

reg CensusTowns  NEAR_DIST_km bank_hundred d2- d17, robust
predict yhat1
gen yhat1swig = ( yhat1 >=.5)
gen correct_predict1 = (yhat1swig ==1 & CensusTowns ==1| yhat1swig ==0 & CensusTowns ==0)
sum correct_predict1
tab correct_predict1

reg CensusTowns nearest_dist_city  bank_hundred d2- d17, robust
predict yhat2
gen yhat2swig = ( yhat2 >=.5)
gen correct_predict2 = (yhat2swig ==1 & CensusTowns ==1| yhat2swig ==0 & CensusTowns ==0)
tab correct_predict2

reg CensusTowns nearest_dist_city NEAR_DIST_km  road_dis_city_dis bank_hundred d2- d17 , robust
predict yhat3
gen yhat3swig = ( yhat3 >=.5)
gen correct_predict3 = (yhat3swig ==1 & CensusTowns ==1| yhat3swig ==0 & CensusTowns ==0)
tab correct_predict3

reg  CensusTowns nearest_dist_city  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007, robust
predict yhat4
gen yhat4swig = ( yhat4 >=.5)
gen correct_predict4 = (yhat4swig ==1 & CensusTowns ==1| yhat4swig ==0 & CensusTowns ==0)
tab correct_predict4

reg  CensusTowns NEAR_DIST_km  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007, robust
predict yhat5
gen yhat5swig = ( yhat5 >=.5)
gen correct_predict5 = (yhat5swig ==1 & CensusTowns ==1| yhat5swig ==0 & CensusTowns ==0)
tab correct_predict5

reg  CensusTowns NEAR_DIST_km nearest_dist_city road_dis_city_dis  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007, robust
predict yhat6
gen yhat6swig = ( yhat6 >=.5)
gen correct_predict6 = (yhat6swig ==1 & CensusTowns ==1| yhat6swig ==0 & CensusTowns ==0)
tab correct_predict6

drop  yhat* yhat*swig correct_predict*



******Goodness of fit  of Table 4 *************

logit  CensusTowns  NEAR_DIST_km bank_hundred d2- d17
predict yhat1
gen yhat1swig = ( yhat1 >=.5)
gen correct_predict1 = (yhat1swig ==1 & CensusTowns ==1| yhat1swig ==0 & CensusTowns ==0)
sum correct_predict1
tab correct_predict1

logit  CensusTowns nearest_dist_city  bank_hundred d2- d17 
predict yhat2
gen yhat2swig = ( yhat2 >=.5)
gen correct_predict2 = (yhat2swig ==1 & CensusTowns ==1| yhat2swig ==0 & CensusTowns ==0)
tab correct_predict2

logit  CensusTowns nearest_dist_city NEAR_DIST_km  road_dis_city_dis bank_hundred d2- d17 
predict yhat3
gen yhat3swig = ( yhat3 >=.5)
gen correct_predict3 = (yhat3swig ==1 & CensusTowns ==1| yhat3swig ==0 & CensusTowns ==0)
tab correct_predict3

logit  CensusTowns nearest_dist_city  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
predict yhat4
gen yhat4swig = ( yhat4 >=.5)
gen correct_predict4 = (yhat4swig ==1 & CensusTowns ==1| yhat4swig ==0 & CensusTowns ==0)
tab correct_predict4

logit  CensusTowns NEAR_DIST_km  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
predict yhat5
gen yhat5swig = ( yhat5 >=.5)
gen correct_predict5 = (yhat5swig ==1 & CensusTowns ==1| yhat5swig ==0 & CensusTowns ==0)
tab correct_predict5

logit  CensusTowns NEAR_DIST_km nearest_dist_city road_dis_city_dis  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
predict yhat6
gen yhat6swig = ( yhat6 >=.5)
gen correct_predict6 = (yhat6swig ==1 & CensusTowns ==1| yhat6swig ==0 & CensusTowns ==0)
tab correct_predict6


drop  yhat* yhat*swig correct_predict*

******Goodness of fit  of Table 5 *************
probit  CensusTowns  NEAR_DIST_km bank_hundred d2- d17
predict yhat1
gen yhat1swig = ( yhat1 >=.5)
gen correct_predict1 = (yhat1swig ==1 & CensusTowns ==1| yhat1swig ==0 & CensusTowns ==0)
sum correct_predict1
tab correct_predict1

probit CensusTowns nearest_dist_city  bank_hundred d2- d17 
predict yhat2
gen yhat2swig = ( yhat2 >=.5)
gen correct_predict2 = (yhat2swig ==1 & CensusTowns ==1| yhat2swig ==0 & CensusTowns ==0)
tab correct_predict2

probit CensusTowns nearest_dist_city NEAR_DIST_km  road_dis_city_dis bank_hundred d2- d17 
predict yhat3
gen yhat3swig = ( yhat3 >=.5)
gen correct_predict3 = (yhat3swig ==1 & CensusTowns ==1| yhat3swig ==0 & CensusTowns ==0)
tab correct_predict3

probit  CensusTowns nearest_dist_city  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
predict yhat4
gen yhat4swig = ( yhat4 >=.5)
gen correct_predict4 = (yhat4swig ==1 & CensusTowns ==1| yhat4swig ==0 & CensusTowns ==0)
tab correct_predict4

probit  CensusTowns NEAR_DIST_km  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
predict yhat5
gen yhat5swig = ( yhat5 >=.5)
gen correct_predict5 = (yhat5swig ==1 & CensusTowns ==1| yhat5swig ==0 & CensusTowns ==0)
tab correct_predict5

probit  CensusTowns NEAR_DIST_km nearest_dist_city road_dis_city_dis  bank_hundred d2- d17 if Nearestcitynoofbanks ~= 1007
predict yhat6
gen yhat6swig = ( yhat6 >=.5)
gen correct_predict6 = (yhat6swig ==1 & CensusTowns ==1| yhat6swig ==0 & CensusTowns ==0)
tab correct_predict6








